package com.spring.springboot.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

import com.spring.springboot.interceptor.LoggerInterceptor;
import com.spring.springboot.interceptor.SessionInterceptor;

/**
*@author LSY
*Time: 2018年12月7日下午5:56:58
*
*
*/
@Configuration
public class InterceptorConfiguration implements WebMvcConfigurer{

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		//登录拦截器
		//registry.addInterceptor(new SessionInterceptor())
		//.excludePathPatterns("/servlet/**")
		//.excludePathPatterns("/static/**")
		//.excludePathPatterns("/yin/resources/**")
		//.excludePathPatterns("*.jpg")
		//.addPathPatterns("/**");
		
		
		//日志拦截器
		registry.addInterceptor(new LoggerInterceptor()).addPathPatterns("/**");
		
	}
	@Bean
	public InternalResourceViewResolver setupViewResolver(){
		InternalResourceViewResolver resolver = new InternalResourceViewResolver();
		resolver.setPrefix("/WEB-INF/jsp/");
		resolver.setSuffix(".jsp");
		return resolver;
	}
	
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/yin/static/**").addResourceLocations("classpath:/static/");//		super.addResourceHandlers(registry);
	}
	
	@Override
	public void addViewControllers(ViewControllerRegistry registry) {
		registry.addViewController("/login").setViewName("login");
		registry.addViewController("/main").setViewName("main");
	}
}
